package com.ruoyi.web.controller.market.special;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.account.enums.ActionTypeEnum;
import com.ruoyi.account.service.IAccountItemSpecialHisService;
import com.ruoyi.account.service.IAccountItemSpecialService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.db.domain.AccountItemSpecial;
import com.ruoyi.db.domain.AccountItemSpecialHis;
import com.ruoyi.db.domain.SpecialCostomInfo;
import com.ruoyi.db.domain.SpecialCostomItemInfo;
import com.ruoyi.special.service.ISpecialCostomInfoService;
import com.ruoyi.special.service.ISpecialCostomItemInfoService;
import com.ruoyi.special.service.ISpecialDataInfoService;
import com.ruoyi.special.service.ISpecialMemberService;
import com.ruoyi.web.service.IMemberInfoHandleService;
import com.ruoyi.web.wapper.AccountItemSpecialHisWapper;
import com.ruoyi.web.wapper.SpecialDataInfoWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 渠道信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-04
 */
@Controller
@RequestMapping("/special/agency/account")
public class SpecialAgencyAccountController extends BaseController
{
    private String prefix = "special/agency/account";

    @Autowired
    ISpecialCostomInfoService specialCostomInfoService;
    @Autowired
    IMemberInfoHandleService memberInfoHandleService;
    @Autowired
    ISpecialDataInfoService specialDataInfoService;
    @Autowired
    ISpecialCostomItemInfoService specialCostomItemInfoService;
    @Autowired
    IAccountItemSpecialHisService accountItemSpecialHisService;
    @Autowired
    IAccountItemSpecialService accountItemSpecialService;

    @RequiresPermissions("special:agency:account")
    @GetMapping("")
    public String view(ModelMap modelMap)
    {

        List<Map<String, String>> actionTypeList = ActionTypeEnum.getListMap();
        modelMap.put("actionTypeList", actionTypeList);

        SysUser sysUser = getSysUser();

        BigDecimal accountAmount = BigDecimal.ZERO;
        if (!sysUser.isAdmin()){
            AccountItemSpecial accountItemSpecial = accountItemSpecialService.selectAccountItemSpecialByDeptId(sysUser.getDeptId());
            accountAmount = accountItemSpecial.getAvaliableAmount();
        }

        modelMap.put("accountAmount", accountAmount);

        return prefix + "/list";
    }

    /**
     * 任务列表
     * @param
     * @return
     */
    @RequiresPermissions("special:agency:account")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountItemSpecialHis accountItemSpecialHis)
    {

        SysUser sysUser = getSysUser();
        if (!sysUser.isAdmin()){
            // 设置，查询
            accountItemSpecialHis.setDeptId(sysUser.getDeptId());
        }

        // 查询用户列表数据
        startPage();
        List<Map<String, Object>> mapList = accountItemSpecialHisService.selectAccountItemSpecialHisListMap(accountItemSpecialHis);
        mapList = new AccountItemSpecialHisWapper(mapList).wrap();

        TableDataInfo tableDataInfo = getDataTable(mapList);
        return tableDataInfo;
    }

}
